package _12反射案例_根据配置文件输出;

import java.io.FileInputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Properties;

public class Test {
    public static void main(String[] args) throws Exception{
        //1.读取配置文件
        Properties properties = new Properties();
        properties.load(new FileInputStream("D:\\黑马java培训班\\代码\\itcast\\JavaSE\\day13\\src\\config.properties"));

        String className = (String) properties.get("className");
        String methodName = (String) properties.get("methodName");

        //2.获取字节码对象
        Class<?> aClass = Class.forName(className);
        //3.获取构造方法
        Constructor<?> constructor = aClass.getConstructor();
        //4.根据构造方法创建对象
        Object o = constructor.newInstance();

        //5.要执行的方法
        Method method = aClass.getMethod(methodName);

        //6.执行方法
        method.invoke(o);


    }
}
